//
//  YMOperateVideoDetailVC.m
//  YMMedical
//
//  Created by y s on 2023/7/20.
//

#import "YMOperateVideoDetailVC.h"
#import "YMMainPlayerVC.h"

@interface YMOperateVideoDetailVC ()<YMPlayerViewDelegate>

@property (nonatomic, strong) YMMainPlayerView *vPlayer;
@property (nonatomic, strong) UILabel *lblTitle;
@property (nonatomic, strong) UILabel *lblDate;

@property (nonatomic, copy) NSString *videoUrl;


@end

@implementation YMOperateVideoDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.vPlayer pause];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    [self.vPlayer playWithUrlString:_videoUrl];
}
#pragma mark -- UI
- (void)setUI{
    self.view.backgroundColor = STheme.D9;
    [self showNavTitle:KLanguage(@"operate_video_txt")];
    [self.view addSubview:self.vPlayer];
    [self.view addSubview:self.lblTitle];
    [self.view addSubview:self.lblDate];
    
    [self.lblTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.vPlayer.bounds.size.height+[SFitUtil fit:15]);
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
    }];
    [self.lblDate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lblTitle.mas_bottom).offset([SFitUtil fit:15]);
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
    }];
    _videoUrl = @"";
    if (_dict != nil){
        self.lblTitle.text = [SDataUtil stringOf:_dict[@"ufwm5h3hjvu3f0bq"]];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        NSDate *date = [formatter dateFromString:[SDataUtil stringOf:_dict[@"created_at"] valid:@""]];
        formatter.dateFormat = @"yyyy-MM-dd";
        
        self.lblDate.text = [NSString stringWithFormat:@"%@ 上传",[formatter stringFromDate:date]];
        NSArray *arrVideo = [SDataUtil arrayOf:_dict[@"b2fpmprchh9sgoaa"]];
        if (arrVideo.count > 0){
            NSDictionary *dictTemp = [SDataUtil dictOf:arrVideo.firstObject];
            _videoUrl = [SDataUtil stringOf:dictTemp[@"url"] valid:@""];
        }
    }
}

#pragma mark -- YMPlayerViewDelegate
- (void)playStart{
}
- (void)playPause{
}
- (void)playStop{
}
- (void)playFinished{
}
- (void)clickPlayerFullScreen:(YMMainPlayerView *)playerView{
    YMMainPlayerVC *vc = [[YMMainPlayerVC alloc] init];
    vc.isPlaying = self.vPlayer.isPlaying;
    vc.isShowFull = YES;
    vc.vPlayer = self.vPlayer;
    WEAK_SELF;
    vc.backAction = ^{
        weakSelf.vPlayer.delegate = weakSelf;
        [weakSelf.view addSubview:weakSelf.vPlayer];
        [weakSelf.vPlayer mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.mas_equalTo(0);
            make.height.mas_equalTo([SFitUtil fit:210]);
        }];
    };
    vc.hidesBottomBarWhenPushed = YES;
    [SJumpUtil pushVC:vc animated:NO];
}


#pragma mark -- setter and getter
- (YMMainPlayerView *)vPlayer{
    if (_vPlayer == nil){
        _vPlayer = [[YMMainPlayerView alloc] init];
        _vPlayer.delegate = self;
        _vPlayer.frame = CGRectMake( 0, 0, SCREEN_WIDTH, [SFitUtil fit:210]);
    }
    return _vPlayer;
}
- (UILabel *)lblTitle{
    if (_lblTitle == nil){
        _lblTitle = [SThemeUtil boldLabel:@"" color:0x3D3D3D fontSize:16];
        _lblTitle.numberOfLines = 0;
    }
    return _lblTitle;
}
- (UILabel *)lblDate{
    if (_lblDate == nil){
        _lblDate = [SThemeUtil boldLabel:@"" color:STheme.H_D3 fontSize:12];
    }
    return _lblDate;
}


@end
